package withouther.system.plugins.quartz.config;

import org.quartz.Scheduler;
import org.quartz.spi.JobFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import java.io.IOException;
import java.util.Properties;

/**
 * @ClassName QuartzConfigration
 * @Auther: tzq
 * @Date: 2021/2/19 15:13
 * @Description:
 */
@Configuration
public class QuartzConfigration {

//    @Autowired
//    private JobFactory jobFactory;

//    @Bean
//    public SchedulerFactoryBean schedulerFactoryBean() {
//        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
//        try {
//            schedulerFactoryBean.setOverwriteExistingJobs(true);
//            schedulerFactoryBean.setQuartzProperties(quartzProperties());
////            schedulerFactoryBean.setJobFactory(jobFactory);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return schedulerFactoryBean;
//    }
    // 指定quartz.properties，可在配置文件中配置相关属性
//    @Bean
//    public Properties quartzProperties() throws IOException {
//        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
//        propertiesFactoryBean.setLocation(new ClassPathResource("/config/quartz.properties"));
//        propertiesFactoryBean.afterPropertiesSet();
//        return propertiesFactoryBean.getObject();
//    }

    // 创建schedule
//    @Bean(name = "scheduler")
//    public Scheduler scheduler() {
//        return schedulerFactoryBean().getScheduler();
//    }

}
